package mao.leetcode.others.leetcode203;

public class Solution {

    public ListNode removeElements(ListNode head, int val) {
        if(head == null) return null;
        while(head != null){
            if (head.val == val) head=head.next;
            else break;
        }
        if (head == null) return null;
        ListNode cur = head;
        while (cur.next != null){
            if (cur.next.val == val) cur.next=cur.next.next;
            else cur=cur.next;
        }
        return head;
    }

    public class ListNode {
        int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }

}
